home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / libiberty / spaces.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-24  |  1.4 KB  |  66 lines

  1. /* Allocate memory region filled with spaces.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  
  20. NAME
  21.  
  22.     spaces -- return a pointer to a buffer full of spaces
  23.  
  24. SYNOPSIS
  25.  
  26.     char *spaces (int count)
  27.  
  28. DESCRIPTION
  29.  
  30.     Returns a pointer to a memory region filled with the specified
  31.     number of spaces and null terminated.  The returned pointer is
  32.     valid until at least the next call.
  33.     
  34. BUGS
  35.  
  36. */
  37.  
  38.  
  39. char *
  40. spaces (count)
  41.   int count;
  42. {
  43.   register char *t;
  44.   static char *buf;
  45.   static int maxsize;
  46.   extern char *malloc ();
  47.   extern void free ();
  48.  
  49.   if (count > maxsize)
  50.     {
  51.       if (buf)
  52.     {
  53.       free (buf);
  54.     }
  55.       buf = malloc (count + 1);
  56.       for (t = buf + count ; t != buf ; )
  57.     {
  58.       *--t = ' ';
  59.     }
  60.       maxsize = count;
  61.       buf[count] = '\0';
  62.     }
  63.   return (buf + maxsize - count);
  64. }
  65.  
  66.